{include file="public/common" /}
{if condition="!empty($back)"}
<button class="layui-btn" onclick="history.back()">返回</button>
{/if}
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
    <legend> {$f_name?$f_name:"社区商品类型"} </legend>
</fieldset>

<!--活动商品--->
<div style="margin:5px;">
    <table class="layui-table">
        <thead>
        <tr>
            <td colspan="3"> <button class="layui-btn" onclick="category_view(0,{$pid},{$deep})" >添加商品类型</button> </td>
        </tr>
        <tr>
            <th style="text-align: center;">id</th>
            <th style="text-align: center;">商品名称</th>
            <th style="text-align: center;">操作</th>
        </tr>
        </thead>
        <tbody>
        {volist name="data" id="item"}
        <tr>
            <td>{$item.id}</td>
            <td>{$item.category_name}</td>
            <td style="text-align: center;">
                <button   class="layui-btn " onclick="category_view('{$item.id}',{$pid})">编辑</button>
                <button class="layui-btn layui-btn-danger" onclick="del_one('{$item.id}')">删除</button>
                {if condition="$deep != 3"}
                &nbsp; &nbsp;|
                <a class="layui-btn layui-btn-normal" href="{:addon_url('admin://goods/goods_category')}?pid={$item.id}&deep={$deep}">管理子专题</a>
                {/if}
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
    {$data->render()}
</div>


<script>
    /**
     * 加载商品分类管理新增/编辑视图
     * @param id
     * @param pid
     */
    function category_view(id,pid,deep)
    {
        layer.open({
            type: 2,
            title: false,
            offset: '50px',
            area: ['800px', '500px'],
            id: 'editlayer',
            cancel: function (index, layero) {
                location.reload();
                layer.close(index)
            },
            content: ["{:addon_url('admin://goods/category_view')}?id=" + id +"&pid="+pid+"&deep="+deep]
        });
    }
    function del_one(id){
        var s = confirm("确认删除");
        if(s){
            $.ajax({
                url:"{:addon_url('admin://goods/del_promotion_goods')}",
                data:{
                    id:id
                },
                success:function(res){
                    console.log(res);
                    if(res.code==0)
                    {
                        location.reload();
                    }
                    else
                    {
                        alert(res.data);
                    }
                }
            });
        }
    }
</script>